package com.google.gson.internal.bind;

import com.google.gson.b.a;
import com.google.gson.b.c;
import com.google.gson.b.d;
import com.google.gson.i;
import com.google.gson.internal.bind.TypeAdapter.Factory;
import com.google.gson.internal.g;
import com.google.gson.j;
import com.google.gson.k;
import com.google.gson.l;
import com.google.gson.m;
import com.google.gson.p;
import com.google.gson.q;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.sql.Timestamp;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.UUID;

public final class y {
    public static final Factory A = a(StringBuffer.class, z);
    public static final TypeAdapter B = new TypeAdapter() {
        public URL a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            String h = aVar.h();
            return !"null".equals(h) ? new URL(h) : null;
        }

        public void a(d dVar, URL url) throws IOException {
            dVar.b(url == null ? null : url.toExternalForm());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory C = a(URL.class, B);
    public static final TypeAdapter D = new TypeAdapter() {
        public URI a(a aVar) throws IOException {
            URI uri = null;
            if (aVar.f() == c.NULL) {
                aVar.j();
            } else {
                try {
                    String h = aVar.h();
                    if (!"null".equals(h)) {
                        uri = new URI(h);
                    }
                } catch (Throwable e) {
                    throw new k(e);
                }
            }
            return uri;
        }

        public void a(d dVar, URI uri) throws IOException {
            dVar.b(uri == null ? null : uri.toASCIIString());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory E = a(URI.class, D);
    public static final TypeAdapter F = new TypeAdapter() {
        public InetAddress a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return InetAddress.getByName(aVar.h());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, InetAddress inetAddress) throws IOException {
            dVar.b(inetAddress == null ? null : inetAddress.getHostAddress());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory G = b(InetAddress.class, F);
    public static final TypeAdapter H = new TypeAdapter() {
        public UUID a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return UUID.fromString(aVar.h());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, UUID uuid) throws IOException {
            dVar.b(uuid == null ? null : uuid.toString());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory I = a(UUID.class, H);
    public static final Factory J = new Factory() {
        public TypeAdapter create(l lVar, com.google.gson.a.a aVar) {
            if (aVar.a() != Timestamp.class) {
                return null;
            }
            final TypeAdapter a = lVar.a(Date.class);
            return new TypeAdapter(this) {
                final /* synthetic */ AnonymousClass11 b;

                public Timestamp a(a aVar) throws IOException {
                    Date date = (Date) a.b(aVar);
                    return date != null ? new Timestamp(date.getTime()) : null;
                }

                public void a(d dVar, Timestamp timestamp) throws IOException {
                    a.a(dVar, timestamp);
                }

                public /* synthetic */ Object b(a aVar) throws IOException {
                    return a(aVar);
                }
            };
        }
    };
    public static final TypeAdapter K = new TypeAdapter() {
        public Calendar a(a aVar) throws IOException {
            int i = 0;
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            aVar.c();
            int i2 = 0;
            int i3 = 0;
            int i4 = 0;
            int i5 = 0;
            int i6 = 0;
            while (aVar.f() != c.END_OBJECT) {
                String g = aVar.g();
                int m = aVar.m();
                if ("year".equals(g)) {
                    i6 = m;
                } else if ("month".equals(g)) {
                    i5 = m;
                } else if ("dayOfMonth".equals(g)) {
                    i4 = m;
                } else if ("hourOfDay".equals(g)) {
                    i3 = m;
                } else if ("minute".equals(g)) {
                    i2 = m;
                } else if ("second".equals(g)) {
                    i = m;
                }
            }
            aVar.d();
            return new GregorianCalendar(i6, i5, i4, i3, i2, i);
        }

        public void a(d dVar, Calendar calendar) throws IOException {
            if (calendar == null) {
                dVar.f();
                return;
            }
            dVar.d();
            dVar.a("year");
            dVar.a((long) calendar.get(1));
            dVar.a("month");
            dVar.a((long) calendar.get(2));
            dVar.a("dayOfMonth");
            dVar.a((long) calendar.get(5));
            dVar.a("hourOfDay");
            dVar.a((long) calendar.get(11));
            dVar.a("minute");
            dVar.a((long) calendar.get(12));
            dVar.a("second");
            dVar.a((long) calendar.get(13));
            dVar.e();
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory L = b(Calendar.class, GregorianCalendar.class, K);
    public static final TypeAdapter M = new TypeAdapter() {
        public Locale a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            StringTokenizer stringTokenizer = new StringTokenizer(aVar.h(), "_");
            String nextToken = stringTokenizer.hasMoreElements() ? stringTokenizer.nextToken() : null;
            String nextToken2 = stringTokenizer.hasMoreElements() ? stringTokenizer.nextToken() : null;
            String nextToken3 = stringTokenizer.hasMoreElements() ? stringTokenizer.nextToken() : null;
            return (nextToken2 == null && nextToken3 == null) ? new Locale(nextToken) : nextToken3 == null ? new Locale(nextToken, nextToken2) : new Locale(nextToken, nextToken2, nextToken3);
        }

        public void a(d dVar, Locale locale) throws IOException {
            dVar.b(locale == null ? null : locale.toString());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory N = a(Locale.class, M);
    public static final TypeAdapter O = new TypeAdapter() {
        public j a(a aVar) throws IOException {
            j iVar;
            switch (aVar.f()) {
                case NUMBER:
                    return new p(new g(aVar.h()));
                case BOOLEAN:
                    return new p(Boolean.valueOf(aVar.i()));
                case STRING:
                    return new p(aVar.h());
                case NULL:
                    aVar.j();
                    return l.a;
                case BEGIN_ARRAY:
                    iVar = new i();
                    aVar.a();
                    while (aVar.e()) {
                        iVar.a(a(aVar));
                    }
                    aVar.b();
                    return iVar;
                case BEGIN_OBJECT:
                    iVar = new m();
                    aVar.c();
                    while (aVar.e()) {
                        iVar.a(aVar.g(), a(aVar));
                    }
                    aVar.d();
                    return iVar;
                default:
                    throw new IllegalArgumentException();
            }
        }

        public void a(d dVar, j jVar) throws IOException {
            if (jVar == null || jVar.j()) {
                dVar.f();
            } else if (jVar.i()) {
                p m = jVar.m();
                if (m.p()) {
                    dVar.a(m.a());
                } else if (m.o()) {
                    dVar.a(m.f());
                } else {
                    dVar.b(m.b());
                }
            } else if (jVar.g()) {
                dVar.b();
                Iterator it = jVar.l().iterator();
                while (it.hasNext()) {
                    a(dVar, (j) it.next());
                }
                dVar.c();
            } else if (jVar.h()) {
                dVar.d();
                for (Entry entry : jVar.k().o()) {
                    dVar.a((String) entry.getKey());
                    a(dVar, (j) entry.getValue());
                }
                dVar.e();
            } else {
                throw new IllegalArgumentException("Couldn't write " + jVar.getClass());
            }
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory P = a(j.class, O);
    public static final Factory Q = a(Enum.class);
    public static final TypeAdapter a = new TypeAdapter() {
        public BitSet a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            BitSet bitSet = new BitSet();
            aVar.a();
            c f = aVar.f();
            int i = 0;
            while (f != c.END_ARRAY) {
                boolean z;
                switch (f) {
                    case NUMBER:
                        if (aVar.m() == 0) {
                            z = false;
                            break;
                        }
                        z = true;
                        break;
                    case BOOLEAN:
                        z = aVar.i();
                        break;
                    case STRING:
                        String h = aVar.h();
                        try {
                            if (Integer.parseInt(h) == 0) {
                                z = false;
                                break;
                            }
                            z = true;
                            break;
                        } catch (NumberFormatException e) {
                            throw new q("Error: Expecting: bitset number value (1, 0), Found: " + h);
                        }
                    default:
                        throw new q("Invalid bitset value type: " + f);
                }
                if (z) {
                    bitSet.set(i);
                }
                i++;
                f = aVar.f();
            }
            aVar.b();
            return bitSet;
        }

        public void a(d dVar, BitSet bitSet) throws IOException {
            if (bitSet == null) {
                dVar.f();
                return;
            }
            dVar.b();
            for (int i = 0; i < bitSet.length(); i++) {
                dVar.a((long) (bitSet.get(i) ? 1 : 0));
            }
            dVar.c();
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory b = a(BitSet.class, a);
    public static final TypeAdapter c = new TypeAdapter() {
        public Boolean a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return aVar.f() == c.STRING ? Boolean.valueOf(Boolean.parseBoolean(aVar.h())) : Boolean.valueOf(aVar.i());
            } else {
                aVar.j();
                return null;
            }
        }

        public void a(d dVar, Boolean bool) throws IOException {
            if (bool == null) {
                dVar.f();
            } else {
                dVar.a(bool.booleanValue());
            }
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final TypeAdapter d = new TypeAdapter() {
        public Boolean a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return Boolean.valueOf(aVar.h());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, Boolean bool) throws IOException {
            dVar.b(bool == null ? "null" : bool.toString());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory e = a(Boolean.TYPE, Boolean.class, c);
    public static final TypeAdapter f = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            try {
                return Byte.valueOf((byte) aVar.m());
            } catch (Throwable e) {
                throw new q(e);
            }
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory g = a(Byte.TYPE, Byte.class, f);
    public static final TypeAdapter h = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            try {
                return Short.valueOf((short) aVar.m());
            } catch (Throwable e) {
                throw new q(e);
            }
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory i = a(Short.TYPE, Short.class, h);
    public static final TypeAdapter j = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            try {
                return Integer.valueOf(aVar.m());
            } catch (Throwable e) {
                throw new q(e);
            }
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory k = a(Integer.TYPE, Integer.class, j);
    public static final TypeAdapter l = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            if (aVar.f() == c.NULL) {
                aVar.j();
                return null;
            }
            try {
                return Long.valueOf(aVar.l());
            } catch (Throwable e) {
                throw new q(e);
            }
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory m = a(Long.TYPE, Long.class, l);
    public static final TypeAdapter n = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return Float.valueOf((float) aVar.k());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory o = a(Float.TYPE, Float.class, n);
    public static final TypeAdapter p = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return Double.valueOf(aVar.k());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory q = a(Double.TYPE, Double.class, p);
    public static final TypeAdapter r = new TypeAdapter() {
        public Number a(a aVar) throws IOException {
            c f = aVar.f();
            switch (f) {
                case NUMBER:
                    return new g(aVar.h());
                case NULL:
                    aVar.j();
                    return null;
                default:
                    throw new q("Expecting number, got: " + f);
            }
        }

        public void a(d dVar, Number number) throws IOException {
            dVar.a(number);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory s = a(Number.class, r);
    public static final TypeAdapter t = new TypeAdapter() {
        public Character a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return Character.valueOf(aVar.h().charAt(0));
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, Character ch) throws IOException {
            dVar.b(ch == null ? null : String.valueOf(ch));
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory u = a(Character.TYPE, Character.class, t);
    public static final TypeAdapter v = new TypeAdapter() {
        public String a(a aVar) throws IOException {
            c f = aVar.f();
            if (f != c.NULL) {
                return f == c.BOOLEAN ? Boolean.toString(aVar.i()) : aVar.h();
            } else {
                aVar.j();
                return null;
            }
        }

        public void a(d dVar, String str) throws IOException {
            dVar.b(str);
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory w = a(String.class, v);
    public static final TypeAdapter x = new TypeAdapter() {
        public StringBuilder a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return new StringBuilder(aVar.h());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, StringBuilder stringBuilder) throws IOException {
            dVar.b(stringBuilder == null ? null : stringBuilder.toString());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };
    public static final Factory y = a(StringBuilder.class, x);
    public static final TypeAdapter z = new TypeAdapter() {
        public StringBuffer a(a aVar) throws IOException {
            if (aVar.f() != c.NULL) {
                return new StringBuffer(aVar.h());
            }
            aVar.j();
            return null;
        }

        public void a(d dVar, StringBuffer stringBuffer) throws IOException {
            dVar.b(stringBuffer == null ? null : stringBuffer.toString());
        }

        public /* synthetic */ Object b(a aVar) throws IOException {
            return a(aVar);
        }
    };

    final class AnonymousClass16 implements Factory {
        final /* synthetic */ Class a;

        AnonymousClass16(Class cls) {
            this.a = cls;
        }

        public TypeAdapter create(l lVar, com.google.gson.a.a aVar) {
            Class a = aVar.a();
            return this.a.isAssignableFrom(a) ? new z(a) : null;
        }
    }

    final class AnonymousClass17 implements Factory {
        final /* synthetic */ Class a;
        final /* synthetic */ TypeAdapter b;

        AnonymousClass17(Class cls, TypeAdapter typeAdapter) {
            this.a = cls;
            this.b = typeAdapter;
        }

        public TypeAdapter create(l lVar, com.google.gson.a.a aVar) {
            return aVar.a() == this.a ? this.b : null;
        }

        public String toString() {
            return "Factory[type=" + this.a.getName() + ",adapter=" + this.b + "]";
        }
    }

    final class AnonymousClass18 implements Factory {
        final /* synthetic */ Class a;
        final /* synthetic */ Class b;
        final /* synthetic */ TypeAdapter c;

        AnonymousClass18(Class cls, Class cls2, TypeAdapter typeAdapter) {
            this.a = cls;
            this.b = cls2;
            this.c = typeAdapter;
        }

        public TypeAdapter create(l lVar, com.google.gson.a.a aVar) {
            Class a = aVar.a();
            return (a == this.a || a == this.b) ? this.c : null;
        }

        public String toString() {
            return "Factory[type=" + this.b.getName() + "+" + this.a.getName() + ",adapter=" + this.c + "]";
        }
    }

    final class AnonymousClass19 implements Factory {
        final /* synthetic */ Class a;
        final /* synthetic */ Class b;
        final /* synthetic */ TypeAdapter c;

        AnonymousClass19(Class cls, Class cls2, TypeAdapter typeAdapter) {
            this.a = cls;
            this.b = cls2;
            this.c = typeAdapter;
        }

        public TypeAdapter create(l lVar, com.google.gson.a.a aVar) {
            Class a = aVar.a();
            return (a == this.a || a == this.b) ? this.c : null;
        }

        public String toString() {
            return "Factory[type=" + this.a.getName() + "+" + this.b.getName() + ",adapter=" + this.c + "]";
        }
    }

    final class AnonymousClass20 implements Factory {
        final /* synthetic */ Class a;
        final /* synthetic */ TypeAdapter b;

        AnonymousClass20(Class cls, TypeAdapter typeAdapter) {
            this.a = cls;
            this.b = typeAdapter;
        }

        public TypeAdapter create(l lVar, com.google.gson.a.a aVar) {
            return this.a.isAssignableFrom(aVar.a()) ? this.b : null;
        }

        public String toString() {
            return "Factory[typeHierarchy=" + this.a.getName() + ",adapter=" + this.b + "]";
        }
    }

    public static Factory a(Class cls) {
        return new AnonymousClass16(cls);
    }

    public static Factory a(Class cls, TypeAdapter typeAdapter) {
        return new AnonymousClass17(cls, typeAdapter);
    }

    public static Factory a(Class cls, Class cls2, TypeAdapter typeAdapter) {
        return new AnonymousClass18(cls, cls2, typeAdapter);
    }

    public static Factory b(Class cls, TypeAdapter typeAdapter) {
        return new AnonymousClass20(cls, typeAdapter);
    }

    public static Factory b(Class cls, Class cls2, TypeAdapter typeAdapter) {
        return new AnonymousClass19(cls, cls2, typeAdapter);
    }
}
